﻿
Imports DataAccess

Public Class BSHoliday

    Public Sub New(ByVal serverName As String)

        ' config server name
        DAHoliday.ConfigServerName(serverName)

    End Sub

    ''' <summary>
    ''' check if day is holiday
    ''' </summary>
    ''' <param name="organNo"></param>
    ''' <param name="day">yyyyMMdd</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function CheckHoliday(ByVal organNo As String, ByVal day As String) As Boolean

        Dim r As Integer = DAHoliday.CheckHoliday(organNo, day)

        If r <> 0 Then

            Return True

        Else

            Return False
            
        End If
        
    End Function


    ''' <summary>
    ''' Get holiday of organization in a month
    ''' </summary>
    ''' <param name="organNo"></param>
    ''' <param name="month"></param>
    ''' <param name="year"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetHoliday(ByVal organNo As String, ByVal month As Integer, ByVal year As Integer) As DataTable

        Dim dayFrom As String = New Date(year, month, 1).ToString("yyyyMMdd")

        Dim dayTo As String = New Date(year, month, Date.DaysInMonth(year, month)).ToString("yyyyMMdd")

        ' Get holiday
        Return DAHoliday.GetHoliday(organNo, dayFrom, dayTo)

    End Function

    ''' <summary>
    ''' Delete holiday
    ''' </summary>
    ''' <param name="organNo"></param>
    ''' <param name="holidayDate"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function DeleteHoliday(ByVal organNo As String, ByVal holidayDate As String) As Boolean

        If DAHoliday.DeleteHoliday(organNo, holidayDate) <> 0 Then

            Return True

        Else

            Return False

        End If

    End Function

    ''' <summary>
    ''' insert holiday
    ''' </summary>
    ''' <param name="organNo"></param>
    ''' <param name="holidayDate"></param>
    ''' <param name="remarks"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function InsertHoliday(ByVal organNo As String, ByVal holidayDate As String, ByVal remarks As String) As Boolean

        Dim r As Object

        If String.IsNullOrEmpty(remarks) Then

            r = DBNull.Value

        Else

            r = remarks

        End If


        If DAHoliday.InsertHoliday(organNo, holidayDate, r) <> 0 Then

            Return True

        Else

            Return False
            
        End If

    End Function

End Class
